﻿IF EXISTS (SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = 'OTMaterialCotizacionInsert')
	BEGIN
		DROP  Procedure  OTMaterialCotizacionInsert
	END
GO
CREATE PROCEDURE [dbo].[OTMaterialCotizacionInsert] 	
	(	
		@OTId					AS INT,
		@ArticuloId				AS VARCHAR(13) = NULL,
		@Papel					AS VARCHAR(255) = NULL,
		@TamanoPliegoMaterial	AS VARCHAR(50) = NULL,
		@TamanoPliegoPrensa		AS VARCHAR(50) = NULL,
		@Cantidad				AS DECIMAL(10,2) = 0,
		@Aumento				AS DECIMAL(10,2) = 0,
		@PliegosTotal			AS DECIMAL(10,2) = 0,
		@NoCotizado				AS DECIMAL(10,2) = 0
	)	
AS
BEGIN	
	SET NOCOUNT ON
	
	DECLARE @Id INT
	DECLARE @PliegosPrensaTotal DECIMAL
	
	SET @PliegosPrensaTotal = @Cantidad + @Aumento + @PliegosTotal + @NoCotizado
	
	INSERT INTO Lit_OTMaterialCotizado
		(OTId, ArticuloId, Papel, TamanoPliegoMaterial, TamanoPliegoPrensa, Cantidad, Aumento, PliegosTotal, PliegosPrensaTotal, NoCotizado)
	VALUES (@OTId, @ArticuloId, @Papel, @TamanoPliegoMaterial, @TamanoPliegoPrensa, @Cantidad, @Aumento, @PliegosTotal, @PliegosPrensaTotal, @NoCotizado)
	
	SELECT @Id = SCOPE_IDENTITY()
	
	SELECT	Id, OTId, ArticuloId, Papel, TamanoPliegoMaterial, TamanoPliegoPrensa,
		 Cantidad, Aumento, PliegosTotal, PliegosPrensaTotal, NoCotizado
	FROM Lit_OTMaterialCotizado
	WHERE Id = @Id
		
	SET NOCOUNT OFF
END
GO